/*
 * ==========================================================================================================
 * 
 *                                               Waterfall demo
 *                                              
 * ==========================================================================================================
 * 
 * 
 * 
 * - Engine control
 * Espace - quit
 * F1 - view console
 * F2 - toggle fullscreen mode
 * F3 - antialiasing
 * F4 - view node model
 * F5 - view collisions
 * F6 - collision fillmode
 * F7 - view partitioner
 * 
 * - Demo control
 * W - move forward
 * S - move backward
 * A - strafe left
 * D - strafe right
 * Left shift - move down
 * Space - move up
 * Mouse move - look
 */

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Waterfall
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        #region fields

        //Engine
        DARE.CDare m_Dare;
        DARE.CScene m_scene;
        DARE.CRender3D m_render;
        DARE.CFirstPersonCamera m_cam;

        bool m_isRightPressed;
        Vector3 m_camDestination;

        DARE.CNode falls;
        DARE.CNode inferiorLake;
        DARE.CNode superiorLake;

        #endregion

        #region ctor

        public Game1()
        {
            m_Dare = new DARE.CDare(this);
        }

        #endregion

        #region methods

        #region load

        private void CreateScene()
        {
            m_scene = new DARE.CScene("scene");

            m_render = new DARE.CRender3D("Particles tutorial 1", new DARE.COctree(-1000, 1000, -1000, 1000, -1000, 1000));
            m_scene.RegisterRenderer(m_render);
            m_render.SkyMgr.CreateSkybox("Sky", "Evening/evening");
            DARE.CNode main = m_render.CreateNode();
            main.AABB = new BoundingBox(Vector3.One * -1000, Vector3.One* 1000);

            #region terrain

            DARE.CNode terrain = main.CreateChild("terrain", DARE.EType.STATIC);
            DARE.CTerrainInfo terrainInfo = new DARE.CTerrainInfo(
                DARE.CResourceMgr.Load<Texture2D>("Heightmaps/falls"), 25, 1);
            DARE.CTerrainModel terrainModel = new DARE.CTerrainModel(terrainInfo, 16, 16);

            terrainModel.SetTexture(DARE.CResourceMgr.Load<Texture2D>("Heightmaps/fallsColormap"),
                DARE.CResourceMgr.Load<Texture2D>("Textures/rock"), Vector2.One * 15,
                DARE.CResourceMgr.Load<Texture2D>("Textures/grass"), Vector2.One * 15,
                DARE.CResourceMgr.Load<Texture2D>("Textures/gravel"), Vector2.One * 15,
                DARE.CResourceMgr.Load<Texture2D>("Textures/ground_red_stones"), Vector2.One * 15);

            terrain = terrainModel.RootNode.SetName("nTerrain");
            m_render.AddNode(terrain);
            terrain.TranslateY(-5);

            terrain.Entity.CreatePhysicTerrain(terrainInfo);

            terrain.Entity.Physic.CollisionType = DARE.APhysicObject.ECollisionType.GROUND;
            
            #endregion

            #region superior water

            superiorLake = main.CreateChild("superiorLake", DARE.EType.STATIC);
            superiorLake.AABB = new BoundingBox(new Vector3(-16, -1, -16), new Vector3(16, 1, 16));
            superiorLake.Rotate(MathHelper.ToRadians(32), 0, 0);
            superiorLake.SetPosition(27, 17f, 49);
            superiorLake.Entity.CreateBasicPlane(35);
            superiorLake.Entity.Model.IsTransparent = true;
            superiorLake.Entity.Model.Effect.ColorMapTiles = Vector2.One * 2;
            superiorLake.Entity.Model.Effect.ColorMapOffset = Vector2.UnitX * 0.5f;
            superiorLake.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            superiorLake.Entity.Model.Effect.ColorMapTiles1 = Vector2.One * 2;
            superiorLake.Entity.Model.Effect.ColorMap1 = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            Texture2D color = new Texture2D(m_Dare.GraphicsDevice, 1, 1);
            Color[] c = new Color[1] { new Color(.5f, .5f, 0, 1) };
            color.SetData(c);
            superiorLake.Entity.Model.Effect.MultiTexturingMap = color;
            superiorLake.Entity.Model.Effect.ColorMapTiles2 = Vector2.One * 2;
            superiorLake.Entity.Model.Effect.ColorMap2 = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            superiorLake.Entity.Model.Effect.ColorMapTiles3 = Vector2.One * 2;
            superiorLake.Entity.Model.Effect.ColorMap3 = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            superiorLake.Entity.Model.Effect.Alpha = 0.75f;
            superiorLake.Entity.Model.Effect.IsMultiTexturingActive = true;
            superiorLake.Entity.Model.CullMode = CullMode.None;

            #endregion

            #region inferior water

            inferiorLake = main.CreateChild("inferiorLake", DARE.EType.STATIC);
            inferiorLake.AABB = new BoundingBox(new Vector3(-64, -1, -64), new Vector3(64, 1, 64));
            inferiorLake.SetPosition(0, 3, 0);
            inferiorLake.Entity.CreateBasicPlane(128);
            inferiorLake.Entity.Model.IsTransparent = true;
            inferiorLake.Entity.Model.Effect.ColorMapTiles = Vector2.One * 5;
            inferiorLake.Entity.Model.Effect.ColorMapOffset = Vector2.UnitX * 0.5f;
            inferiorLake.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            inferiorLake.Entity.Model.Effect.ColorMapTiles1 = Vector2.One * 5;
            inferiorLake.Entity.Model.Effect.ColorMap1 = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            inferiorLake.Entity.Model.Effect.MultiTexturingMap = color;
            inferiorLake.Entity.Model.Effect.ColorMapTiles2 = Vector2.One * 5;
            inferiorLake.Entity.Model.Effect.ColorMap2 = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            inferiorLake.Entity.Model.Effect.ColorMapTiles3 = Vector2.One * 5;
            inferiorLake.Entity.Model.Effect.ColorMap3 = DARE.CResourceMgr.Load<Texture2D>("Textures/water0hk");
            inferiorLake.Entity.Model.Effect.Alpha = 0.5f;
            inferiorLake.Entity.Model.Effect.IsMultiTexturingActive = true;
            inferiorLake.Entity.Model.CullMode = CullMode.None;

            #endregion
   
            #region falls

            /*DARE.CNode falls = main.CreateChild("falls", DARE.EType.STATIC);
            falls.AABB = new BoundingBox(new Vector3(-64, -64, -64), new Vector3(64, 64, 64));
            falls.SetPosition(10, 6, 30);
            falls.Entity.CreateBasicPlane(10);
            falls.SetScale(1, 1, 2);
            falls.Rotate(MathHelper.ToRadians(30), MathHelper.ToRadians(-75), 0);

            DARE.CNode falls2 = main.CreateChild("falls2", DARE.EType.STATIC);
            falls2.AABB = new BoundingBox(new Vector3(-64, -64, -64), new Vector3(64, 64, 64));
            falls2.SetPosition(13.28f, 16.3f, 33.28f);
            falls2.Entity.CreateBasicPlane(10);
            falls2.SetScale(1.2f, 1, .40f);
            falls2.Rotate(MathHelper.ToRadians(30), MathHelper.ToRadians(-20), 0);*/

            DARE.CNode waterfallsParticles = main.CreateChild("waterfallsParticles", DARE.EType.DYNAMIC);
            DARE.CDirectionalParticle waterParticle = new DARE.CDirectionalParticle();
            waterParticle.FadeInDuration = 300;
            waterParticle.FadeOutDuration = 300;
            waterParticle.FinalColor = Color.White;
            waterParticle.FinalSize = Vector2.One;
            waterParticle.Forces = -Vector3.UnitY * 0.00001f;// -Vector3.UnitY * 0.08f;
            waterParticle.InitialColor = Color.White;
            waterParticle.InitialSize = Vector2.One * 3;
            waterParticle.LifeTime = 1000;
            waterParticle.Texture = DARE.CResourceMgr.Load<Texture2D>("Textures/flare_low");

            DARE.CSquareEmitter waterfallsEmitter = new DARE.CSquareEmitter("waterfallsEmitter");
            waterfallsEmitter.EmissionInterval = 10;
            waterfallsEmitter.EmitPerEmission = 5;
            waterfallsEmitter.MaxParticlesSimultaneous = 2500;
            waterfallsEmitter.ReferenceParticle = waterParticle;
            waterfallsEmitter.Velocities = new Vector3(0f, 0.005f, 0f);
            waterfallsEmitter.Rect = Vector2.UnitX * 5;
            waterfallsEmitter.EdgeSpawn = false;

            waterfallsParticles.Entity.AttachEmitter(waterfallsEmitter);
            waterfallsEmitter.IsStarted = true;
            waterfallsParticles.SetPosition(10f, 3, 30);
            waterfallsParticles.Rotate(MathHelper.ToRadians(32), 0, 0);
            waterfallsParticles.AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);


            falls = main.CreateChild("falls", DARE.EType.STATIC);
            falls.AABB = new BoundingBox(new Vector3(-64, -64, -64), new Vector3(64, 64, 64));
            falls.SetPosition(15f, 17, 36.9f);
            falls.Entity.AttachModel(new DARE.CModel("Waterfall", "cascade"));
            falls.SetScale(15, 50, 4);
            falls.Rotate(MathHelper.ToRadians(32), 0, 0);
            falls.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("FX_waterfall1");
            //falls.Entity.Model.Effect.ColorMapTiles = new Vector2(5, 10);
            falls.Entity.Model.CullMode = CullMode.None;

            DARE.CNode fallsRock = main.CreateChild(DARE.EType.STATIC);
            fallsRock.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_A"));//.Entity.Model.IsTransparent = true;
            fallsRock.SetPosition(18, 17, 33);
            fallsRock.SetScale(0.002f, 0.002f, 0.002f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            //fallsRock.Rotate(MathHelper.ToRadians(32), 0, 0);
            DARE.CNode fallsRock2 = main.CreateChild(DARE.EType.STATIC);
            fallsRock2.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_B"));//.Entity.Model.IsTransparent = true;
            fallsRock2.SetPosition(15, 17, 35);
            fallsRock2.SetScale(0.002f, 0.002f, 0.002f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock2.Rotate(0, 0, MathHelper.ToRadians(32));
            fallsRock2.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            DARE.CNode fallsRock3 = main.CreateChild(DARE.EType.STATIC);
            fallsRock3.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_B"));//.Entity.Model.IsTransparent = true;
            fallsRock3.SetPosition(11, 17, 39);
            fallsRock3.SetScale(0.002f, 0.002f, 0.002f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock3.Rotate(MathHelper.ToRadians(32), MathHelper.ToRadians(32), 0);
            fallsRock3.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            DARE.CNode fallsRock4 = main.CreateChild(DARE.EType.STATIC);
            fallsRock4.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_A"));//.Entity.Model.IsTransparent = true;
            fallsRock4.SetPosition(8, 16, 34);
            fallsRock4.SetScale(0.004f, 0.004f, 0.004f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock4.Rotate(MathHelper.ToRadians(32), MathHelper.ToRadians(32), 0);
            fallsRock4.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            DARE.CNode fallsRock5 = main.CreateChild(DARE.EType.STATIC);
            fallsRock5.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_B"));//.Entity.Model.IsTransparent = true;
            fallsRock5.SetPosition(12, 17, 37.6f);
            fallsRock5.SetScale(0.001f, 0.001f, 0.001f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock5.Rotate(MathHelper.ToRadians(32), MathHelper.ToRadians(32), 0);
            fallsRock5.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            DARE.CNode fallsRock6 = main.CreateChild(DARE.EType.STATIC);
            fallsRock6.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_B"));//.Entity.Model.IsTransparent = true;
            fallsRock6.SetPosition(13, 17, 37.5f);
            fallsRock6.SetScale(0.001f, 0.001f, 0.001f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock6.Rotate(MathHelper.ToRadians(32), MathHelper.ToRadians(32), 0);
            fallsRock6.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");


            DARE.CNode fallsRock7 = main.CreateChild(DARE.EType.STATIC);
            fallsRock7.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_A"));//.Entity.Model.IsTransparent = true;
            fallsRock7.SetPosition(40, 20, -41);
            fallsRock7.SetScale(0.002f, 0.002f, 0.002f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock7.Rotate(0, 0, 0);
            fallsRock7.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            DARE.CNode fallsRock8 = main.CreateChild(DARE.EType.STATIC);
            fallsRock8.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_B"));//.Entity.Model.IsTransparent = true;
            fallsRock8.SetPosition(40, 20, -37);
            fallsRock8.SetScale(0.002f, 0.002f, 0.002f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock8.Rotate(MathHelper.ToRadians(45), 0, 0);
            fallsRock8.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");
            DARE.CNode fallsRock9 = main.CreateChild(DARE.EType.STATIC);
            fallsRock9.Entity.AttachModel(new DARE.CModel("fallsRock", "rocher_B"));//.Entity.Model.IsTransparent = true;
            fallsRock9.SetPosition(37, 20, -39);
            fallsRock9.SetScale(0.002f, 0.002f, 0.002f).AABB = new BoundingBox(Vector3.One * -5, Vector3.One * 5);
            fallsRock9.Rotate(0, 0, 0);
            fallsRock9.Entity.Model.Effect.ColorMap = DARE.CResourceMgr.Load<Texture2D>("Textures/rock");

            #endregion

            #region deco

            DARE.CNode fireEmitterNode = main.CreateChild(DARE.EType.DYNAMIC);
            DARE.CNode fireEmitterNode2 = main.CreateChild(DARE.EType.DYNAMIC);
            fireEmitterNode.AABB = new BoundingBox(new Vector3(-30, -20, -30), new Vector3(30, 200, 30));
            fireEmitterNode2.AABB = new BoundingBox(new Vector3(-30, -20, -30), new Vector3(30, 200, 30));

            DARE.CDirectionalParticle fireParticle = new DARE.CDirectionalParticle();
            fireParticle.FadeInDuration = 100;
            fireParticle.FadeOutDuration = 200;
            fireParticle.FinalColor = Color.Red;
            fireParticle.FinalSize = Vector2.One * 0.5f;
            fireParticle.Forces = Vector3.UnitY * 0.002f / 1000.0f;//Vector3.Zero;// -Vector3.UnitY * 0.5f;
            fireParticle.InitialColor = Color.Yellow;
            fireParticle.InitialSize = new Vector2(1f, 2);
            fireParticle.LifeTime = 2000;
            fireParticle.Texture = DARE.CResourceMgr.Load<Texture2D>("Textures/streak");

            DARE.CConeEmitter coneEmitter = new DARE.CConeEmitter("Cone emitter");
            coneEmitter.EmissionInterval = 10;
            coneEmitter.EmitPerEmission = 10;
            coneEmitter.MaxParticlesSimultaneous = 5000;
            coneEmitter.ReferenceParticle = fireParticle;
            coneEmitter.Velocities = Vector3.One * 0.0001f;
            coneEmitter.Ray = 2.5f;
            coneEmitter.Angle = MathHelper.Pi / 4.0f;
            coneEmitter.IsStarted = true;
            fireEmitterNode.Entity.AttachEmitter(coneEmitter);
            fireEmitterNode.SetPosition(39, 19.5f, -38);

            DARE.CDirectionalParticle fireParticle3 = new DARE.CDirectionalParticle();
            fireParticle3.FadeInDuration = 100;
            fireParticle3.FadeOutDuration = 200;
            fireParticle3.FinalColor = Color.Black;
            fireParticle3.FinalSize = Vector2.One * 10f;
            fireParticle3.Forces = Vector3.UnitY * 0.00001f / 1000.0f;//Vector3.Zero;// -Vector3.UnitY * 0.5f;
            fireParticle3.InitialColor = Color.White;
            fireParticle3.InitialSize = new Vector2(2f, 2);
            fireParticle3.LifeTime = 5000;
            fireParticle3.Texture = DARE.CResourceMgr.Load<Texture2D>("Textures/smoke");

            DARE.CConeEmitter coneEmitter3 = new DARE.CConeEmitter("Cone emitter2");
            coneEmitter3.EmissionInterval = 100;
            coneEmitter3.EmitPerEmission = 1;
            coneEmitter3.MaxParticlesSimultaneous = 5000;
            coneEmitter3.ReferenceParticle = fireParticle3;
            coneEmitter3.Velocities = Vector3.One * 0.005f;
            coneEmitter3.Ray = 2.5f;
            coneEmitter3.Angle = MathHelper.Pi / 2f;
            coneEmitter3.IsStarted = true;
            fireEmitterNode.Entity.AttachEmitter(coneEmitter3);



            DARE.CDirectionalParticle fireParticle2 = new DARE.CDirectionalParticle();
            fireParticle2.FadeInDuration = 100;
            fireParticle2.FadeOutDuration = 200;
            fireParticle2.FinalColor = Color.Black;
            fireParticle2.FinalSize = Vector2.One * 10f;
            fireParticle2.Forces = Vector3.UnitY * 0.00001f / 1000.0f;//Vector3.Zero;// -Vector3.UnitY * 0.5f;
            fireParticle2.InitialColor = new Color(100, 0, 0);
            fireParticle2.InitialSize = new Vector2(1f, 1);
            fireParticle2.LifeTime = 5000;
            fireParticle2.Texture = DARE.CResourceMgr.Load<Texture2D>("Textures/smoke");

            DARE.CConeEmitter coneEmitter2 = new DARE.CConeEmitter("Cone emitter4");
            coneEmitter2.EmissionInterval = 50;
            coneEmitter2.EmitPerEmission = 1;
            coneEmitter2.MaxParticlesSimultaneous = 5000;
            coneEmitter2.ReferenceParticle = fireParticle2;
            coneEmitter2.Velocities = Vector3.One * 0.005f;
            coneEmitter2.Ray = 4f;
            coneEmitter2.Angle = 2f * MathHelper.Pi / 6.0f;
            coneEmitter2.IsStarted = true;
            fireEmitterNode2.Entity.AttachEmitter(coneEmitter2);
            fireEmitterNode2.SetPosition(-45.3f, 9.3f, -42);

            #endregion
            

            m_cam = new DARE.CFirstPersonCamera("fpc");
            m_cam.ViewPort.DisplayRectangle = new Rectangle(0, 0, DARE.CDare.Instance.Config.Video.ResolutionWidth, DARE.CDare.Instance.Config.Video.ResolutionHeight);
            m_render.CameraMgr.RegisterCamera(m_cam);
            m_render.EffectMgr.LighteningEnabled = true;

            m_render.EffectMgr.DirectionalLight0DiffuseColor = Color.White;
            m_render.EffectMgr.DirectionalLight0DiffuseIntensity = .8f;
            m_render.EffectMgr.DirectionalLight0Direction = -Vector3.UnitY;

            m_cam.Position = new Vector3(-60, 50, 40);
            m_cam.LookAt(Vector3.Zero);

        }
        
        protected override void LoadContent()
        {
            // general configuration
            m_Dare.Config.General.WindowTitle = "Waterfall";
            m_Dare.Config.General.ShowMouseCursor = true;
            m_Dare.Config.General.ShowDebugConsole = false;

            // video configuration
            m_Dare.Config.Video.SetResolution(1024, 768);
            m_Dare.Config.Video.FullScreen = false;
            m_Dare.Config.Video.MultiSampling = true;

            // start the engine
            m_Dare.RockNRoll();

            // create things :D
            CreateScene();

            
        }

        #endregion

        #region run

        protected override void Update(GameTime gameTime)
        {
            ProcessInput(gameTime);
            ProcessMovement(gameTime);
            base.Update(gameTime);

            falls.Entity.Model.Effect.ColorMapOffset += Vector2.UnitY * DARE.CDare.Instance.Config.Time.TimeSinceLastFrame * 0.00008f;
            inferiorLake.Entity.Model.Effect.ColorMapOffset += Vector2.UnitX * 0.000006f * DARE.CDare.Instance.Config.Time.TimeSinceLastFrame;
            inferiorLake.Entity.Model.Effect.ColorMapOffset1 += Vector2.UnitY * 0.000009f * DARE.CDare.Instance.Config.Time.TimeSinceLastFrame;
            superiorLake.Entity.Model.Effect.ColorMapOffset += Vector2.UnitX * 0.00006f * DARE.CDare.Instance.Config.Time.TimeSinceLastFrame;
            superiorLake.Entity.Model.Effect.ColorMapOffset1 += Vector2.UnitX * 0.00009f * DARE.CDare.Instance.Config.Time.TimeSinceLastFrame;
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        #endregion

        #region inputs

        public void ProcessInput(GameTime gameTime)
        {
            ProcessKeyReleased(gameTime);
            ProcessKeyPressed(gameTime);
            ProcessMouseMoved(gameTime);
            ProcessMousePressed(gameTime);
            ProcessMouseReleased(gameTime);
        }

        /// <summary>
        /// Here you can set the actions to do when a key is pressed (as exiting whenever the key Escape is pressed).
        /// </summary>
        private void ProcessKeyPressed(GameTime gameTime)
        {
            foreach (Keys key in DARE.CDare.Instance.InputMgr.Keyboard.KeyPressedEvent)
            {
                switch (key)
                {
                    case Keys.Escape: this.Exit(); break;
                    case Keys.F1: m_Dare.DebugMgr.DebugConsoleEnabled = !m_Dare.DebugMgr.DebugConsoleEnabled; break;
                    case Keys.F2: m_Dare.Config.Video.FullScreen = !m_Dare.Config.Video.FullScreen; break;
                    case Keys.F3: m_Dare.Config.Video.MultiSampling = !m_Dare.Config.Video.MultiSampling; break;
                    case Keys.F4: m_render.ShowModelNode = !m_render.ShowModelNode; break;
                    case Keys.F5: m_render.ShowCollision = !m_render.ShowCollision; break;
                    case Keys.F6: m_render.CollisionFillMode = m_render.CollisionFillMode == FillMode.WireFrame ? FillMode.Solid : FillMode.WireFrame; break;
                    case Keys.F7: m_render.Partitioner.Show = !m_render.Partitioner.Show; break; 


                    // camera movement
                    case Keys.W: --m_camDestination.Z; break;
                    case Keys.S: ++m_camDestination.Z; break;
                    case Keys.A: --m_camDestination.X; break;
                    case Keys.D: ++m_camDestination.X; break;
                    //
                }
            }
        }


        /// <summary>
        /// Here you can set the actions to do when a key is released (as exiting whenever the key Escape is released).
        /// </summary>
        private void ProcessKeyReleased(GameTime gameTime)
        {
            foreach (Keys key in DARE.CDare.Instance.InputMgr.Keyboard.KeyReleasedEvent)
            {
                switch (key)
                {
                    // camera movement
                    case Keys.W: ++m_camDestination.Z; break;
                    case Keys.S: --m_camDestination.Z; break;
                    case Keys.A: ++m_camDestination.X; break;
                    case Keys.D: --m_camDestination.X; break;
                }
            }
        }


        /// <summary>
        /// Here you can set the actions to do when the mouse has moved.
        /// </summary>
        private void ProcessMouseMoved(GameTime gameTime)
        {
            Vector2 mouseMoved = DARE.CDare.Instance.InputMgr.Mouse.MoveEvent.Movement;

            // first cam orientation
            if (DARE.CDare.Instance.InputMgr.Mouse.IsCentered != m_isRightPressed)
                DARE.CDare.Instance.InputMgr.Mouse.IsCentered = m_isRightPressed;
            if (DARE.CDare.Instance.InputMgr.Mouse.HasMoved && m_isRightPressed)
            {
                m_cam.Rotate(new Vector3(-mouseMoved.Y / 2000.0f, -mouseMoved.X / 2000.0f, 0.0f));
            }
        }

        /// <summary>
        /// Here you can set the actions to do when a button on the mouse has been pressed.
        /// </summary>
        private void ProcessMousePressed(GameTime gameTime)
        {
            foreach (DARE.CMouse.EButton button in DARE.CDare.Instance.InputMgr.Mouse.ButtonPressedEvent)
            {
                switch (button)
                {
                    case DARE.CMouse.EButton.LEFT:
                        foreach (DARE.CRayCast.CIntersectInfo iInfo in m_render.RayCast.IntersectAllFromCenterToMouse(1000, 3))
                        {
                            switch (iInfo.node.Entity.Physic.CollisionType)
                            {
                                case DARE.APhysicObject.ECollisionType.GROUND:
                                    DARE.CDare.Instance.DebugMgr.DebugConsole.WriteLine("intersection : " + iInfo.pos.ToString());
                                    break;

                            }
                        }
                        break;
                    case DARE.CMouse.EButton.MIDDLE:
                        break;
                    case DARE.CMouse.EButton.RIGHT:
                        m_isRightPressed = true;
                        break;
                }
            }
        }

        /// <summary>
        /// Here you can set the actions to do when a button on the mouse has been released.
        /// </summary>
        private void ProcessMouseReleased(GameTime gameTime)
        {
            foreach (DARE.CMouse.EButton button in DARE.CDare.Instance.InputMgr.Mouse.ButtonReleasedEvent)
            {
                switch (button)
                {
                    case DARE.CMouse.EButton.LEFT:
                        break;
                    case DARE.CMouse.EButton.MIDDLE:
                        break;
                    case DARE.CMouse.EButton.RIGHT:
                        m_isRightPressed = false;
                        break;
                }
            }
        }

        #endregion

        #region movements

        protected void ProcessMovement(GameTime gameTime)
        {
            m_cam.Translate(m_camDestination * 0.01f * (float)gameTime.ElapsedGameTime.TotalMilliseconds);
        }

        #endregion


        #endregion
    }
}
